#!/bin/bash

if [ -n "$1" ]; then
  data_date=$1
else
  data_date=`date -d "-1 days" +%F`
fi

sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT log_id, user_id, product_id, sku_id, session_id, event_type, event_time, page_url, status, source_type, stay_time, seed, activity, device_type, ip_address, province, city, network_type, is_new_user, create_time, update_time FROM mzy.ods_product_log WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_product_log/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'


sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT product_id, product_name, category_id, brand_id, user_id, start_id, is_favorite, is_cart, price, price_level, zf_flag, status, create_time, update_time FROM mzy.ods_product_order WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_product_order/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT sku_id, product_id, sku_name, price, original_price, create_time, update_time FROM mzy.ods_order_detail WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_order_detail/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT user_id, gender, age, register_time, last_login_time, user_level, create_time, province, city FROM mzy.ods_user_info WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_user_info/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT category_id, category_name, product_id, level, status, create_time, update_time FROM mzy.ods_product_category WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_product_category/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT brand_id, brand_name, brand_desc, country, status, create_time, update_time FROM mzy.ods_product_brand WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_product_brand/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT review_id, product_id, user_id, sku_id, rating, create_time FROM mzy.ods_product_review WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_product_review/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'

sqoop import \
--connect  jdbc:mysql://node101:3306/mzy \
--username root \
--password 123456 \
--query 'SELECT content_id, product_id, content_type, title, view_count, create_time FROM mzy.ods_payment_method WHERE $CONDITIONS AND 1=1;' \
--delete-target-dir \
--target-dir "hdfs://node101:8020/warehouse/product_basic/ods_payment_method/${data_date}" \
--as-textfile \
--fields-terminated-by '\t' \
--num-mappers 1 \
--null-string '\\N' \
--null-non-string '\\N'